﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ajaxPage_fotoEtiket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Islem = Request.QueryString["Islem"];

        Cihazlar NCihaz = new Cihazlar();

        if (Islem == "Ekle")
        {
            string Cihaz_Adi = Request.QueryString["Cihaz_Adi"];
            string IP_Adresi = Request.QueryString["IP_Adresi"];
            string MAC_Adresi = Request.QueryString["Mac_Adresi"];
            string Kisi = Request.QueryString["Kisi"];
            string Birim_Adi = Request.QueryString["Birim_Adi"];
            string Top = Request.QueryString["Top"];
            string Left = Request.QueryString["Left"];
            string Kat_No = Request.QueryString["Kat_No"];
            string Oda_No = Request.QueryString["Oda_No"];

            NCihaz.Cihaz_Adi = Cihaz_Adi;
            NCihaz.Ip_Adresi = IP_Adresi;
            NCihaz.Mac_Adresi = MAC_Adresi;
            NCihaz.Ilgili_Kisi = Kisi;

            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = WebConfigurationManager.ConnectionStrings["baglanti"].ToString();
            cn.Open();
            SqlCommand cm = new SqlCommand("Select Birim_ID from Birimler Where Birim_Adi='" + Birim_Adi.Trim() + "'", cn);
            SqlDataReader dr = cm.ExecuteReader();
            if (dr.Read())
            {
                NCihaz.Birim_ID = Convert.ToInt32(dr["Birim_ID"]);
            }
            dr.Close();
            cm.CommandText = "Select Kayit_ID from Kayitlar Where Birim_ID='" + NCihaz.Birim_ID + "' And Kat_No='" + Kat_No + "' And Oda_No='" + Oda_No + "'";
            dr = cm.ExecuteReader();
            if (dr.Read())
            {
                NCihaz.Kayit_ID = Convert.ToInt32(dr["Kayit_ID"]);
            }
            dr.Dispose();
            cm.Dispose();
            cn.Close();
            cn.Dispose();

            String[] temp = new String[2];
            temp = Top.Split('p');
            Top = (Convert.ToInt32(temp[0]) + 200).ToString();
            Top = Top + "px";

            NCihaz.Sag = Left;
            NCihaz.Ust = Top;
            NCihaz.EklemeZamani = DateTime.Now;
            db.Insert("Cihazlar", NCihaz, false);
        }
        else if (Islem == "Sil")
        {
            string Cihaz_ID = Request.QueryString["Cihaz_ID"];
            db.Delete("Cihazlar", "where Cihaz_ID=" + Cihaz_ID);
        }
    }
}
